<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="../../themes/gray/easyui.css" />
		<link rel="stylesheet" href="../../themes/icon.css" />
		<script type="text/javascript" src="../../scripts/jquery-1.8.0.min.js"></script>
		<script type="text/javascript" src="../../scripts/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../scripts/locale/easyui-lang-zh_CN.js"></script>
		<style>
			#main {
				width: 960px;
				height: auto;
			}
			
			.left {
				width: 700px;
				height: auto;
			}
			
			.right {
				width: 250px;
				height: auto;
				padding-left: 10px;
			}
			
			.left,
			.right {
				float: left;
			}
			
			.daily-my-stu {
				color: #BCBCBC;
				font-size: 12px;
			}
			
			.daily-my-content {
				border: 1px dashed #F00;
				border-color: #BCBCBC;
				margin-top: 10px;
				padding-left: 20px;
				height: 130px;
			}
			/*清除浮动代码*/
			
			.clearfloat:after {
				display: block;
				clear: both;
				content: "";
				visibility: hidden;
				height: 0
			}
			
			.clearfloat {
				zoom: 1
			}
			/*清除浮动代码结束*/
			
			.content-panel-back {
				width: 960px;
				height: 40px;
				background: #EEEEEE;
			}
			
			.input-button {
				background: #F4F4F4;
				border: none;
				overflow: hidden;
				padding: 8px;
			}
			
			.content-panel-text {
				width: 955px;
				height: 60px;
				border: 1px dashed #F00;
				border-color: #BCBCBC;
			}
		</style>
		<script type="text/javascript">
			function onDateC() {
				var mydateInput = document.getElementById("date-date");
				var titleT = document.getElementById("title-time");
				var date = new Date($("#date-date").val().replace(/-/g, "/"));
				var end = new Date();
				if (date > end) {
					alert("对不起，您的输入有误！");
					wol();
					return false;
				}
				var dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
				day = date.getDay();
				var week = "";
				if (day == 0)
					week = '星期日';
				if (day == 1)
					week = '星期一';
				if (day == 2)
					week = '星期二';
				if (day == 3)
					week = '星期三';
				if (day == 4)
					week = '星期四';
				if (day == 5)
					week = '星期五';
				if (day == 6)
					week = '星期六';
				titleT.innerText = "XXX 项目日报 " + dateString + " (" + week + ")";
				refresh_view();
			}

			function wol() {
				var mydateInput = document.getElementById("date-date");
				var titleT = document.getElementById("title-time");
				var date = new Date();
				var dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
				mydateInput.value = dateString;
				day = date.getDay();
				var week = "";
				if (day == 0)
					week = '星期日';
				if (day == 1)
					week = '星期一';
				if (day == 2)
					week = '星期二';
				if (day == 3)
					week = '星期三';
				if (day == 4)
					week = '星期四';
				if (day == 5)
					week = '星期五';
				if (day == 6)
					week = '星期六';
				titleT.innerText = "XXX 项目日报 " + dateString + " (" + week + ")";
			}
			$(function() {
				wol();
				$("#btn_submit_edit").css("display", "none");
				refresh_view();
				$('#new_form').form({
					//url: '../../journal/' + $("urlSubfix").val() + 'Journal.ajax',
					onSubmit: function() {
						alert("id");
						if ($(this).form('validate')) {
							return true; //验证是否为空
						} else {
							return false;
						}
					},
					success: function(data) {
						alert(data);
						var obj = $.parseJSON(data); //将json字符串转换为object对象
						if (obj.success) {
							$.messager.alert('提示', obj.message, 'info', function() {
								refresh_view();
							});
						} else {
							$.messager.alert('错误', obj.message, 'error');
						}
					}
				});
				//事件绑定，点击提交就提交表单
				$('#btn_submit').bind('click', function() {
					alert("btn_submit  " + $("#urlSubfix").val());
					var file = $("#input-file");
					if ($.trim(file.val()) == '') {
						alert("请选择文件");
						return false;
					}
					$('#new_form').attr("action", "../../journal/addJournal.ajax");
					$("#new_form").submit();
				});
				//事件绑定，点击提交就提交表单
				$('#btn_submit_edit').bind('click', function() {
					alert("btn_submit_edit  " + $("#urlSubfix").val());
					var file = $("#input-file");
					if ($.trim(file.val()) == '') {
						alert("请选择文件");
						return false;
					}
					$('#new_form').attr("action", "../../journal/editJournal.ajax");
					$("#new_form").submit();
				});
				$("#edit_journal").bind('click', function() {
					$(".content-panel-back").show();
					$(".content-panel-text").show();
					$("#btn_submit_edit").show();
					$("#btn_submit").css("display", "none");
				});
				$("#download").bind('click', function() {
					//生成的文件名
					var filename = $("#file-time").html();
					var name = $("#download").attr("value");
					alert(filename + "  " + name);
					window.location.href = "../../journal/downloadJournal.ajax?filename=" + filename + "&name=" + name;
				});
			});

			function refresh_view() {
				//var projectId = $.getUrlParam("projectId");
				var jtime = $("#date-date").val();
				//$("#pid-value").val(1);
				$.ajax({
					type: "post",
					url: "../../journal/viewJournal.ajax",
					dateType: 'JSON',
					cache: false,
					data: {
						pid: 1,
						type: 0,
						jTime: jtime
					},
					error: function() {},
					success: function(data) {
						var obj = $.parseJSON(data);
						//alert(obj.journal.id);
						if (obj.success) {
							init_view(obj);
						} else {
							alert("init__");
							$(".content-panel-back").show();
							$(".content-panel-text").show();
							$(".p1").hide();
							$("#p0").html("未提交");
							$("#p0").css("line-height", "80px");
						}
					}
				});
			}

			function init_view(obj) {
				$("urlSubfix").val("edit");
				$("#jid").val(obj.journal.id);
				var date = new Date($("#date-date").val().replace(/-/g, "/"));
				var dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
				//$("#file-time").val(dateString+" 日志");
				$("#file-time").html(dateString);
				$("#download").val(obj.journal.file);
				//alert($("#jid").attr("value"));
				$(".content-panel-back").hide();
				$(".content-panel-text").hide();
				$(".p1").show();
				$("#p0").html("已提交");
				$("#p0").css("line-height", "25px");
			}
		</script>

		<title>Insert title here</title>
	</head>

	<body>
		<form id="new_form" method="post" name="form_name" enctype="multipart/form-data">
			<div id="main" class="clearfloat">
				<div class="left">
					<p id="title-time">XXX 项目日报 2016-11-23 （星期三）</p>
					<p class="daily-my-stu">提交情况</p>
					<div class="daily-my-content">
						<p id="p0" style="line-height: 25px; font-size: 14px; color: #BBB;">已提交
						</p>
						<p class="p1">
							附件：<a id="file-time">2016-12-26</a>日志 &nbsp&nbsp&nbsp&nbsp<a id="download"  href="javascript:void(0)">点击下载</a>
						</p>
						<a class="p1" id="edit_journal" style="line-height: 25px; font-size: 14px;" href="javascript:void(0)">编辑 </a>
					</div>
				</div>
				<div class="right">
					<p>请选择日期</p>
					<input type="date" name="jTime" id="date-date" onchange="onDateC()" />
				</div>
			</div>

			<hr align="left" style="height: 2px; border: none; border-top: 2px dotted #F0F0F0; width: 960px; margin-top: 60px;" />

			<div class="content-panel-back">
				<div class="left" style="line-height: 40px;">工作日报</div>
				<div class="right">
					<a id="btn_submit_edit" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" style="line-height: 40px; margin-top: 6px;">提交修改</a>
					<a id="btn_submit" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" style="line-height: 40px; margin-top: 6px;">确认提交</a>
				</div>
			</div>
			<div class="content-panel-text">
				<input class="input-button" id="input-file" type="file" value="选择附件" name="tempfile" style="line-height: 22px; margin: 10px;" />
			</div>

			</div>
			<input type="text" hidden="true" id="jid" name="id" />
			<input type="text" hidden="true" name="type" value="0" />
			<input type="text" hidden="true" name="pid" value="1" id="pid-value" />
			<input type="text" hidden="true" name="pname" value="中国石油" />
		</form>
	</body>

</html>